package com.简单项目.零钱通;

import java.util.Date;
import java.util.Scanner;
import java.text.SimpleDateFormat;

public class 零钱通 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        boolean loop = true;
        String detail = "";  //零钱通明细
        double money = 0;  // 金额
        double yu_e = 0;      // 余额
        Date date = new Date();  // 获取当前时间
        SimpleDateFormat sdf = new SimpleDateFormat();

        do {
            System.out.println("\n----------------零钱通菜单----------------");
            System.out.println("\t\t\t1.零钱通明细");
            System.out.println("\t\t\t2.收益入账");
            System.out.println("\t\t\t3.消费");
            System.out.println("\t\t\t4.退出");
            System.out.println("\t\t\t请选择1-4");
            System.out.println("----------------零钱通菜单----------------\n");


            String key = "";
            key = scanner.next();
            switch (key) {
                case "1":
                    System.out.println("----------------零钱通菜单----------------");
                    System.out.println("流水类型\t金额\t\t\t时间\t\t\t\t余额");
                    System.out.println(detail);
                    break;

                case "2":
                    System.out.println("请输入存入金额");
                    money = scanner.nextDouble();
                    if (money <= 0) {
                        System.out.println("存入金额必须大于0");
                        break;
                    }
                    yu_e += money;
                    date = new Date();
                    detail += "\n收益入账\t+" + money + "\t" + sdf.format(date) + "\t" + yu_e;
                    break;


                case "3":
                    System.out.println("请输入支出金额");
                    money = scanner.nextDouble();

                    if (money <= 0) {
                        System.out.println("支出金额必须大于零");
                        break;
                    }

                    if (money > yu_e) {
                        System.out.println("余额不足");
                        break;
                    }

                    yu_e -= money;
                    date = new Date();
                    detail += "\n支出\t\t-" + money + "\t" + sdf.format(date) + "\t" + yu_e;
                    break;


                case "4":
                    System.out.println("确定要退出吗");

                    while (true) {
                        String choice = scanner.next();
                        if (choice.equals("y")) {
                            System.out.println("退出了项目");
                            loop = false;
                            break;
                        }

                        if (choice.equals("n")) {
                            break;
                        } else System.out.println("选择有误，请重新选择\"y\" 或 \"n\"");
                    }

                    break;
                default:
                    System.out.println("选择有误，请重新选择");
            }

        } while (loop);


    }
}
